#include "zad7library.hpp"
#include "zad7app.hpp"
#include <cstdlib>
#include <iostream>
#include <math.h>

using namespace std;

namespace amodlisz {

		Function * AppEuler::createFunction(){
			return new Euler(0,1,2,&f);
		}

		Function * AppEulerpc::createFunction(){
			return new Eulerpc(0,1,2,&f);
		}

		Function * AppRK2::createFunction(){
			return new RK2(0,1,2,&f);
		}

	        Application::Application(AppFactory * factory) {
	                f = factory->createFunction();
	                delete factory;
	        }
		
		double* Application::Run(){
			return f->function(100);
		}

		void Application::Normalize(double * soln){
			double norm=0;
 			double h=1.0/100.0;
			for (int k=1;k<=100;k++){         // compare error
			norm=max(norm, fabs(exact(k*h)-soln[k]));
			cout<<"exact: "<<exact(k*h)<<" sol: "<<soln[k]<<endl;
			}
			cout<<"Max norm wybranej metody to: "<<norm<<endl;
		}

	AppFactory * createApplication() {
		int l=0;	
		cout<<"Wybierz metode (0 - Euler) (1 - Eulerpc) (2 - KR2)"<<endl;
		cin>>l;
		while(true){
			switch(l){
				case 0: return new AppEuler; break;
				case 1: return new AppEulerpc; break;
				case 2: return new AppRK2; break;
				default:cout<<"Błędny Wybór"<<endl; break;
			}
			cout<<"Wybierz metode (0 - Euler) (1 - Eulerpc) (2 - KR2)"<<endl;
			cin>>l;
		}
	
	}

}
